package com.smh.demo1.a20;

import org.springframework.beans.DirectFieldAccessor;

import java.util.Date;

/**
 * @author shiminghui
 * @date 2025/5/1 15:02
 * @description: TODO
 */
public class TestFiledAccessor {
    public static void main(String[] args) {

        MyBean myBean = new MyBean();
        // 用的反射直接对字段进行赋值
        DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(myBean);
        directFieldAccessor.setPropertyValue("age", "12");
        directFieldAccessor.setPropertyValue("name", "smh");
        directFieldAccessor.setPropertyValue("birthDate", "2004/10/26");

        System.out.println(myBean);


    }

    static class MyBean {
        private int age;
        private String name;
        private Date birthDate;

        @Override
        public String toString() {
            return "MyBean{" +
                    "age=" + age +
                    ", name='" + name + '\'' +
                    ", birthDate=" + birthDate +
                    '}';
        }
    }
}
